﻿#include "dialognet.h"
#include "ui_dialognet.h"
#include <QFileDialog>
#include <QDebug>

DialogNet::DialogNet(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogNet)
{
    ui->setupUi(this);
    settings_ = new QSettings(QApplication::applicationDirPath() + "/NetworkConfig.ini", QSettings::IniFormat);
    settings_->setIniCodec("UTF8");
    ui->lineEdit_file->setText(settings_->value("src_path").toString());
    ui->lineEdit_ip->setText(settings_->value("ip_addr").toString());
    if(settings_->value("send_interval").isValid())
        ui->spinBox_interval->setValue(settings_->value("send_interval").toInt());
    if(settings_->value("port").isValid())
        ui->spinBox_port->setValue(settings_->value("port").toInt());
    if(settings_->value("start_frame").isValid())
        ui->spinBox_file_start->setValue(settings_->value("start_frame").toInt());
    if(settings_->value("replay_cnt").isValid())
        ui->spinBox_cycle_times->setValue(settings_->value("replay_cnt").toInt());

}

DialogNet::~DialogNet()
{
    delete ui;
}

void DialogNet::on_pushButton_choose_clicked()
{
    // 选择路径
    QString file_path = QFileDialog::getExistingDirectory(this,"", settings_->value("src_path").toString());
    ui->lineEdit_file->setText(file_path);

    QDir dir(file_path);

    //file_list_=dir.entryList(QDir::Files, QDir::Time| QDir::Reversed);
    file_list_ = dir.entryList(QDir::Files, QDir::Name);
    qDebug()<< file_list_[0];
    settings_->setValue("src_path", file_path);
}

void DialogNet::on_buttonBox_accepted()
{
    QString ip_addr  = ui->lineEdit_ip->text();
    settings_->setValue("ip_addr",ip_addr);

    settings_->setValue(("send_interval"), ui->spinBox_interval->value());
    settings_->setValue("port",	ui->spinBox_port->value());
    settings_->setValue("start_frame", ui->spinBox_file_start->value());
    settings_->setValue("replay_cnt",  ui->spinBox_cycle_times->value());
}
